!lm12
!rm76
Putting S-C Assembler II on the Language Card . . Paul Schlyter

[ Paul is a subscriber in Stockholm, Sweden. ]

Introduction

I have owned the S-C Assembler II for only a little more than three weeks, and already I have stopped using the two other assemblers I used to use before ("Apple Text Processing System" and "DOS Tool Kit Assembler").  Although the others have some powerful features, the S-C Assembler is so much easier to use it now takes me only about half the time to finish an assembly language program as it did before.

The many similarities between the S-C Assembler and Integer BASIC made me curious, so I disassembled the Assembler.  Earlier I have done the same thing with Integer BASIC, Applesoft, and DOS.  It wasn't too long (about a week) that I had a fair understanding of the first third of the assembler.  Then the idea turned up in my head:  "Why not try to relocate it into the language card?"  Another week of sleepless nights and it was up and running!

There were several traps on the way.  It took a long time for me to discover the address stack put into DOS at $1333-133C.  Sometimes I just entered the regular assembler at $1000-24FF and didn't notice anything, sometimes the machine crashed when a DOS error occurred.  But that was a week ago, and the last week nothing like that has happened...now I feel fairly confident that I have found all bytes that need to be relocated.  If anything does turn up, I will let you know.


Why and How

Have you ever thought about how very similar to Integer BASIC the S-C Assembler II is?  It stores its source files as DOS type-I files, and numbers the lines the same way as Integer BASIC.  Just like in Integer BASIC, you have access to all DOS commands.  Well, the similarities don't stop there.  Integer BASIC starts at address $E000 and ends a little bit above $F400; the S-C Assembler starts at $1000 and ends a little bit above $2400.  The byte at $E000 is $20 in Integer BASIC (JSR opcode) while it is $4C in Applesoft (JMP opcode); it is by looking at this byte that DOS decides whether Integer BASIC or Applesoft is the current language.  Well, guess what the byte at $1000 in the S-C Assembler is:  it's $20!

When putting all these facts together, I started to wonder if it wasn't possible to relocate the S-C Assembler up into the Language card, making DOS believe it is in Integer BASIC.  This of course requires that you have Applesoft on the motherboard ROMs, so that DOS will be able to distinguish between the ROM and Language card languages.

Sure enough, it is possible.  I did move it up there, and it works, and it turned out to be really convenient.  The DOS command FP puts me in Applesoft, while INT puts me into the S-C Assembler!  Also, if I am currently in Applesoft and LOAD an S-C Assembler source file (type-I, of course), DOS will automatically start up the assembler!  Can you really ask for more?

To relocate the S-C Assembler into the language card, you need of course a language card (any of the several RAM cards no available will do).  You also need to have Applesoft in ROM on the motherboard (not Integer BASIC).  You also need a relocation program; I used the one in the Programmer's Aid #1 software, which is in the INTBASIC file on the DOS 3.3 System Master.  You could use the one in Bob Sander-Cederlof's article elsewhere in this AAL just as well.


Step-by-step Procedure

1.  Boot the DOS 3.3 System Master.  This will load Integer BASIC into the Language Card.

2.  Type INT to enter Integer BASIC.

3.  Put in the S-C Assembler II disk, and BLOAD ASMDISK 4.0 (do not BRUN it).

4.  Enter the Apple monitor by typing CALL -151.  (Throughout the following steps, be sure you do NOT hit RESET!)

5.  Now that you are in the monitor, type the following commands:

!lm16
C083 C083          (write-enable the language card)

D4D5G              (initialize the relocation program)

E000<1000.24FF^Y*  (specify source and destination
                    blocks for the relocation program.
                    Note that "^Y" means "control-Y".
                    The asterisk at the end IS necessary.)

E000<1000.100E^Y   (relocate the first segment)

.100FM .121E^Y .1282M .1330^Y .133CM .1436^Y

.1438M .147C^Y .14A9M .14DB^Y .141EM .14F3^Y

.14F5M .15D0^Y .15D6M .17A6^Y .17AEM .1A8C^Y

.1A91M .1BB7^Y .1CAEM .2149^Y .2150M .221C^Y .24FFM

!lm20
(The monitor commands on the above four lines relocate the program segments and move the data segments.  They can be typed as shown, or one per line, or even all on one line.  Just be sure to type them correctly -- check and double check -- before pressing RETURN.)
!np
!lm12
6.  The machine code relocator automatically updates any direct address references in the program being relocated.  This saves us a lot of work, but it does not finish the work.  We also have to fix all the address tables and all immediate address references.  Enter the following monitor commands to fix all of these (only one command per line):

!lm16
E042:E2     E254:E2     E334:E0     F234:F1
E227:E7     E259:EB     E336:E0     F239:F0
E22C:E5     E25E:E3     E338:E0     F23E:F0
E231:E0     E263:E0     E33A:E3     F243:F0
E236:E5     E268:E5     E33C:E0     F248:F2
E23B:E1     E26D:F1     E4A3:E4     F24D:F0
E240:E4     E272:E6     E83E:F2     F252:F1
E245:E1     E277:E1     F225:F0     F257:F0
E24A:E6     E27C:E0     F22A:F1     F25C:EE
E24F:E3     E281:EB     F22F:F0     F261:E0

!lm12
7.  The cold start routine in the Assembler must be patched:

    E030:ED E2

    E2E0:AD 83 C0 AD 83 C0 A9 00 85 D9 4C 08 E3 AD 83 C0

    E2F0:AD 83 C0 4C 75 E3

8.  If you wish, you may change the starting address of the Assembler Symbol Table to make more space:

    E011:10

    E2D6:10

9.  If you enter Applesoft from the S-C Assembler, the output hook from DOS will still be connected to the S-C Assembler output routine.  But the assembler will be banked away since now the motherboard ROMs are enabled!  The result is that the Apple will hang.  To cure this problem, you will have to sacrifice the SLOW and FAST commands, and the ability to suspend/abort listings using the space bar and RETURN keys.  This is not such a big sacrifice anyway, since all language card owners have the Autostart Monitor:  you can use control-S to suspend a listing.  You can also use RESET to abort one (provided your language card has a switch and it is in the UP position).  [If you can't bear to part with SLOW and FAST, you can type FP and then hit RESET to get out of the Assembler.]

Here are the patches to eliminate SLOW and FAST:

    E1E9:EA EA EA EA

    E22D:4D 4E 54 68 FF

    E273:FF FF FF
!np
These patches also change FAST to MNT, a command that gracefully enters the monitor.  From the monitor, a control-C will re-enter the S-C Assembler with the current source program intact; a control-B will cold start the S-C Assembler.

10.  Save the completed package on disk with:

     BSAVE LANGASM,A$E000,L$2000.

11.  Modify a copy of the HELLO program from the DOS 3.3 System Master Disk to BLOAD LANGASM instead of INTBASIC, and use this as your HELLO program.  When you boot it will automatically load the S-C Assembler II into your language card.


Parting Shots

Maybe you think that I must have a thorough knowledge of how the S-C Assembler II works internally to be able to do this relocation, but this is not actually the case.  I made a disassembly and also hex and ASCII dumps of the whole assembler, and I also started to untangle the code, but I only really know about a third of the code fairly well.  I still have not the faintest idea of how the actual assembly is performed, although looking at the ASCII dump immediately revealed where the opcode and command tables were located, and the error messages.  I also did find out the places where the error messages are produced...this helps a lot in figuring out what is happening in the code.  And with this not-too-well understanding of the inner workings, and with a lot of trial-and-error, I was able to find all the places where changes needed to be made.

My S-C Assembler has been running from my language card for over a week, and I have used it a lot during this time; all has gone very well.  And believe me, it is SO CONVENIENT to have it there!  I really benefit from the language card, not only when using Pascal or CP/M, but also when I am running DOS.  And I use the S-C Assembler II much more than Integer BASIC, so having the assembler in the language card is really the right thing for me.  Maybe it is for you too!

So, Bob, although you have made an excellent and very easy to use assembler, it is not quite true anymore that the S-C Assembler II is the easiest assembler to use...LANGASM is.  And as you have guessed, LANGASM is nothing but the S-C Assembler II relocated into the language card!

[ If the instructions for making LANGASM leave you breathless, you can order Quarterly Disk #6 ($15.00).  It will include all the source code from this issue and the next two of AAL, and also an EXEC file which will create LANGASM from ASMDISK 4.0.  It will be ready in early March, 1982.  Another shortcut is to order the source code of the S-C Assembler II ($95.00).  Then simply change the origin, modify the SLOW and FAST commands, and re-assemble it.  Voila!  LANGASM! ]

